#kq is the greatest common divisor of x and y 

copy x to i;
copy y to j;

clear need_check;

while i not 0 do;
	incr need_check;
	
	copy i to kq;
	clear i;
end;
while j not 0 do;
	incr need_check;
	copy j to kq;
	clear j;
end;

decr need_check;


while need_check not 0 do;
	copy x to i;
	clear kq;
	while i not 0 do;
		clear got_result;
		clear n;
		
		#calculate x % i ;
		copy x to k;
		incr k;
		while k not 0 do;
			copy k to n;		
			
			clear temp;
			while i not 0 do;
				decr k;
				decr i;
				incr temp;
			end;
			#restore i;
			while temp not 0 do;
				incr i;
				decr temp;
			end;
		end;
		decr n;
		incr n_is_zero;
		while n not 0 do;
			clear n_is_zero;
			clear n;
		end;
		while n_is_zero not 0 do;
			incr got_result;
			clear n_is_zero;
		end;
		#calculate y % i ;
		copy y to k;
		incr k;
		while k not 0 do;
			copy k to n;		
			
			clear temp;
			while i not 0 do;
				decr k;
				decr i;
				incr temp;
			end;
			#restore i;
			while temp not 0 do;
				incr i;
				decr temp;
			end;
		end;
		decr n;
		incr n_is_zero;
		while n not 0 do;
			clear n_is_zero;
			clear n;
		end;
		while n_is_zero not 0 do;
			incr got_result;
			clear n_is_zero;
		end;

		#check got_result
		decr got_result;
		while got_result not 0 do;
			copy i to kq;

			clear i;
			clear got_result;
		end;

		decr i;
	end;

	clear need_check;
end;
